using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GameAOT;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_UIGmHistoryCell : UIBaseNode
    {
        #region Template Generate,don't modify
        protected class UIB_UIN_UIGmHistoryCell
        {
            #region ObjectBinding Generate 
            public IQIGame.Onigao.Framework.ExText txtCommandArgs { protected set; get; }
            public IQIGame.Onigao.Framework.ExText txtName { protected set; get; }
            public IQIGame.Onigao.Framework.ExText txtTime { protected set; get; }
            public IQIGame.Onigao.Framework.ExButton btnExecute { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("txtCommandArgs", out var __tbv0);
                this.txtCommandArgs = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("txtName", out var __tbv1);
                this.txtName = __tbv1;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("txtTime", out var __tbv2);
                this.txtTime = __tbv2;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExButton>("btnExecute", out var __tbv3);
                this.btnExecute = __tbv3;
            }


            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region fields
        string cmd;
        string args = "";


        #endregion fields

        #region properties

        protected UIB_UIN_UIGmHistoryCell ui { get; set; }
        protected UIMsgDispatcher uiMsgDispatcher => _msgDispatcher as UIMsgDispatcher;

        #endregion properties

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_UIGmHistoryCell();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {

        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        /// <summary>
        /// 添加UGUI侦听
        /// </summary>
        protected override void AddUGUIListener()
        {
            this.ui.btnExecute.AddClickEvent(OnClickExecute);
        }



        /// <summary>
        /// 添加全局侦听（MsgDispatcher）
        /// </summary>
        protected override void AddMsgListeners()
        {

        }

        protected override void OnDispose()
        {

        }

        #region methonds

        private void OnClickExecute()
        {
            (this.belongWindow as UIGMList).SendCmd(cmd, args);
        }

        internal void Show(string log)
        {
            string[] t = log.Split("|");
            this.cmd = t[0];
            if (cmd == "exec")
            {
                this.args = t[2];
                this.ui.txtTime.text = t[1];
                TableCenter.gmBatchCmd.DataMap.TryGetValue(int.Parse(args), out var obj);
                this.ui.txtName.text = obj.Remark;
            }
            else
            {
                if (t.Length == 4) this.args = t[3];
                string[] s = args.Split(" ");
                this.ui.txtName.text = t[2];
                if (s.Length == 2) this.ui.txtName.text += "X" + s[1];
            }
            this.ui.txtCommandArgs.text = cmd + " " + args;
            this.ui.txtTime.text = t[1];
        }

        #endregion methonds
    }
}